from django.db import models

# Create your models here.
from django.db import models


# Create your models here.


# 用户表
class UserModel(models.Model):
    username = models.CharField('用户名字', max_length=16)
    password = models.CharField('用户密码', max_length=256)
    position = models.CharField('岗位',max_length=16)
    role = models.CharField('角色',max_length=16)
    permission = models.IntegerField('权限',default=0)
    branch = models.CharField('部门',max_length=16)
    rank = models.CharField('职级',max_length=16)
# 角色表
class RoleModel(models.Model):
    role_name = models.CharField('角色名字', max_length=16)
    # user = models.ForeignKey('UserModel',on_delete=models.CASCADE,verbose_name='用户')
    beizhu = models.CharField('备注',max_length=260)

# 权限表
class PermissionModel(models.Model):
    permission_name = models.CharField('用户权限名称', max_length=256)
    permission_level = models.IntegerField("权限等级",default=0)
    permission_url = models.CharField('用户权限路由', max_length=256)
    beizhu = models.CharField('备注',max_length=260)
    # user = models.ForeignKey('UserModel',on_delete=models.CASCADE,verbose_name='用户')


# 部门表
class BranchModel(models.Model):
    branch_name = models.CharField('部门名称', max_length=16)
    beizhu = models.CharField('备注',max_length=260)
    # user = models.ForeignKey('UserModel',on_delete=models.CASCADE,verbose_name='用户')



# 职级表
class RankModel(models.Model):
    rank_name = models.CharField('职级名称', max_length=256)
    beizhu = models.CharField('备注',max_length=260)
    # user = models.ForeignKey('UserModel',on_delete=models.CASCADE,verbose_name='用户')



# 工资单
class MoneyBomModel(models.Model):
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    work_day = models.IntegerField('出勤天数', null=True, blank=True)
    absenteeism_day = models.IntegerField('旷工天数', null=True, blank=True)
    rest_day = models.IntegerField('请假天数', null=True, blank=True)
    basic_money = models.DecimalField('基本工资', max_digits=8, decimal_places=2, null=True, blank=True)
    rank_money = models.DecimalField('岗位工资', max_digits=8, decimal_places=2, null=True, blank=True)


# 车辆信息
class VehicleModel(models.Model):
    vehicle_type = models.CharField('车辆类型', max_length=16)
    vehicle_number = models.CharField('车牌', max_length=16)
    vehicle_state = models.BooleanField('使用状态', default=False)


# 文件材料表
class FileMaterialsModel(models.Model):
    vehicle_type = models.CharField('文件名称', max_length=16)
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    create_time = models.DateTimeField('创建时间', auto_now_add=True, editable=True, null=True)
    file_address = models.CharField('文件地址', max_length=256)
    file_state = models.BooleanField('是否公开', default=True)
    permission_level = models.IntegerField("等级阅读权限")



# 菜单表


class MenuModel(models.Model):
    menu_name = models.CharField('菜单名称', max_length=16)
    address = models.CharField('路由',max_length=256)
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='son', null=True, verbose_name='父级')


# 发件箱
class SendEmailModel(models.Model):
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    send_address = models.CharField('发件地址', max_length=256)
    send_title = models.CharField('发件标题', max_length=64)
    receive_id = models.IntegerField('收件人ID')
    content = models.TextField('发件内容')


# 收件箱
class ReceiveEmailModel(models.Model):
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    send_email = models.ForeignKey('SendEmailModel', on_delete=models.CASCADE)
    receive_id = models.IntegerField('发件人ID')


# 岗位表
class PositionModel(models.Model):
    position_name = models.CharField('岗位名称',max_length=16)
    beizhu = models.CharField('备注',max_length=260)
    # user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    # role = models.ForeignKey('RoleModel', on_delete=models.CASCADE)
    # permission = models.ForeignKey('PermissionModel', on_delete=models.CASCADE)
    # branch = models.ForeignKey('BranchModel', on_delete=models.CASCADE)
    # rank = models.ForeignKey('RankModel', on_delete=models.CASCADE)


# 登录日志
class LoginLogModel(models.Model):
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    end_time = models.DateTimeField('最后登录时间', auto_now=True, editable=True, null=True)
    login_device = models.CharField('登录设备', max_length=128)
    login_ip = models.CharField('登录IP', max_length=64)
    login_address = models.CharField('登录位置', max_length=128)


# 操作日志
class OperationLogModel(models.Model):
    user = models.ForeignKey('UserModel', on_delete=models.CASCADE)
    permission = models.ForeignKey('PermissionModel', on_delete=models.CASCADE)
    operation_time = models.DateTimeField('操作时间', auto_now=True, editable=True, null=True)
    action = models.CharField('动作内容', max_length=256)


